#! /usr/bin/env python
# -*- coding: utf-8 -*-

from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
from app import app
from app import db
from app.models import User, Role

manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


@manager.command
def admin():
    # from getpass import getpass
    username = input("\_admin username: ")
    password = input("\_admin password: ")
    u = User(username=username, password=password, role_id=1)
    db.session.add(u)
    db.session.commit()
    print('<admin user %s add in database>' % username)


if __name__ == '__main__':

    manager.run()
